##    Copyright 2007 David Blewett
##
##   Licensed under the Apache License, Version 2.0 (the "License");
##   you may not use this file except in compliance with the License.
##   You may obtain a copy of the License at
##
##       http://www.apache.org/licenses/LICENSE-2.0
##
##   Unless required by applicable law or agreed to in writing, software
##   distributed under the License is distributed on an "AS IS" BASIS,
##   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
##   See the License for the specific language governing permissions and
##   limitations under the License.
## Author: David Blewett
## Contact: david@dawninglight.net

"""imap package exception classes."""

#Exceptions
class NotImplemented(Exception): pass
    
class IMAPException(Exception):
    def __init__(self, *args):
        Exception.__init__(self, *args)

class IMAPReadError(IMAPException): 
    def __str__(self):
        return 'IMAP read error: %s' % self.args

class IllegalClientResponse(IMAPException): pass

class IllegalOperation(IMAPException): pass

class IllegalMailboxEncoding(IMAPException): pass

class UnhandledResponse(IMAPException): pass

class NegativeResponse(IMAPException): pass

class NoSupportedAuthentication(IMAPException):
    def __init__(self, serverSupports, clientSupports):
        IMAPException.__init__(self, 'No supported authentication schemes available')
        self.serverSupports = serverSupports
        self.clientSupports = clientSupports

    def __str__(self):
        return (IMAPException.__str__(self)
            + ': Server supports %r, client supports %r'
            % (self.serverSupports, self.clientSupports))

class IllegalServerResponse(IMAPException): pass

class IllegalIdentifierError(IMAPException): pass

class IllegalQueryError(IMAPException): pass

class MismatchedNesting(IMAPException):pass

class MismatchedQuoting(IMAPException):pass

class MailboxException(IMAPException): pass

class MailboxCollision(MailboxException):
    def __str__(self):
        return 'Mailbox named %s already exists' % self.args

class NoSuchMailbox(MailboxException):
    def __str__(self):
        return 'No mailbox named %s exists' % self.args

class ReadOnlyMailbox(MailboxException):
    def __str__(self):
        return 'Mailbox open in read-only state'